module debounce(CLK, NOISY, CLEAN);
	input CLK, NOISY;
	output CLEAN;
	parameter DELAY = 50000;
	parameter DBITS = 16;
	reg [DBITS-1:0] count <= 0;
	reg temp <= NOISY, CLEAN <= NOISY;

	always @(posedge clk) begin
		if (NOISY != temp) begin
			temp <= noisy;
			count <= 0;
		end else if (count == DELAY) begin
			clean <= temp;
		end else begin
			count <= count+1;
		end
	end
endmodule

